<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<%@include file="/WEB-INF/jsp/base/head.jsp"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>权限列表</title>
</head>
<body>
<s:form id="form1" namespace="/system" action="authAction" name="form1" method="post">

	<input type="hidden" id="delURL" value="authAction!authDelete.do" />
	<input type="hidden" id="enabledURL" value="system/authAction!enabled.do" />
	<input type="hidden" id="disabledURL" value="system/authAction!disabled.do" />
	<input type="hidden" id="returnURL" value="system/authAction!getAuthList.do" />
	
	<div class="center_main">
		 <div id="btn-option">
			<a class="add-btn"  id="showNewBox" href="javascript:void(0);" title="新增">新增</a>
			<a class="edit-btn" id="popEdit"       href="javascript:void(0);" title="修改">修改</a>
			<a class="del-btn"  id="delete" href="javascript:void(0)" title="删除">删除</a>
			<a class="enable-btn"  id="enabled"  href="javascript:void(0);" title="启用">启用</a>
			<a class="disable-btn"  id="disabled" href="javascript:void(0);" title="禁用">禁用</a>
		</div>
		<div class="center_left"></div>
	</div>
	<div id="page-top">
		<span>权限管理列表</span>
		<b></b><i></i>
	</div>
  
	<div id="page"> 
		<div id="search">
      		<div class="search-edit-wapper">
				<label for="">权限名称：</label>
			    <input type="text"  class="form-text" name="authorityBizBean.name" value="<s:property value='authorityBizBean.name'/>" />
			</div>
		</div>
	
		<div id="search-btn-wapper">
			<s:submit cssClass="btn"  method="getAuthList" value="查询"></s:submit>
		</div>
            
       	<div id="item-list">
			<table>
			   <thead>
			     <tr>
					<th>选择<input type="checkbox" id="selectAll" /></th>
					<th>序号</th>
					<th>权限名称</th>
					<th>权限状态</th>
					<th>权限描述</th>
				 </tr>
			   </thead>
				<tbody>
					<s:iterator value="authorityBizBeanList" var="r" status="sta"> 
					<tr>
						<td><input type="checkbox" name="authIdList" class="classCheckbox" value='<s:property value="#r.id"/>' /></td>
						<td><s:property value="#sta.index+1"/></td>
						<td><s:property value="#r.name"/></td>
						<td><d:codeItem name="use_yes_no" value="${markDelete}"></d:codeItem>&nbsp;</td>
						<td><s:property value="#r.description"/></td>
					</tr>
					</s:iterator>
					<s:if test="authorityBizBeanList.size == 0">
					    <tr>
					       <td colspan="5">数据暂无!</td>
					    </tr>
					</s:if>
				</tbody>
			</table>
		</div>
    </div>
    </s:form>
    <div id="page-bottom">
    	<b></b><i></i>
		<d:page namespace="/system" action="roleAction!getAuthList">
		</d:page>
	</div>
</body>
<link href="<%=request.getContextPath()%>/css/lightBox.css" rel="stylesheet" type="text/css"/>
<script src="<%=request.getContextPath()%>/js/lightBox.js" type='text/javascript'></script>
<script type="text/javascript">
$(function(){
	$("#showNewBox").click(function(){
		var body = '<form action="authAction!save.do" id="authform" name="authform" method="post">' +
		'<div class="row"><b class="label">权限名称:</b><input name="name" id="name" class="input" />&nbsp;&nbsp;<font color="red" id="message">*</font></div>' +		
		'<div class="row"><b class="label">权限状态:</b>'+
		'<select name="status" id="status" style="margin-top: 5px;">' +
		'<option value="N" />正常</option>'+
		'<option value="Y" />停用</option>'+
		'</select><font color="red">&nbsp;&nbsp;*</font>' +
		'</div>' +
		'<div class="row"><b class="label">备注:</b><textarea name="roleRemark" id="roleRemark" rows="3" class="input" style="textmode:multiline;" onkeydown="if (this.value.length>=200){event.returnValue=false}"></textarea></div>' +
		'</form>';
		var	footer='<div style="text-align:center"><input type="button" value="保存" class="divbtn" id="savaBtn"/><input type="button" value="取消" class="divbtn" id="authcancel" /></div>';
		Box("auth",400,200,body,"新建权限",footer);
	});

	$("#savaBtn").live("click", function(){
		if("" == $("#name").val()){
			$("#message").html("权限名称不能为空！");
			return false;
		} else {
			$("#message").html("*");
		}
		$.ajax({
			   type: "POST",
			   url: "<%=request.getContextPath()%>/system/authAction!save.do",
			   data:{'authorityBizBean.name':$("#name").val(),
				     'authorityBizBean.description':$("#roleRemark").val(),
				     'authorityBizBean.markDelete':$("#status").val()
				    },
			   dataType: "json",
			   async: false,
			   success: function(msg){
						if(msg.msg !=''){
							$("#message").html(msg.msg);
						} else {
							alert("新增权限成功！");
							$("#form1").attr("action", "<%=request.getContextPath()%>/system/authAction!getAuthList.do");
							$("#form1").submit();   
						}
			   }
			});
	});
	
	$("#popEdit").click(function(){
		var item = $("input[name='authIdList']:checked").length;
		if(item != undefined &&  item > 0 && item == 1) {
			$.ajax({
				   type: "POST",
				   url: "<%=request.getContextPath()%>/system/authAction!updatePage.do",
				   data:{'authorityBizBean.id':$("input[name='authIdList']:checked").val()},
				   dataType: "json",
				   async: false,
				   success: function(authorityBizBean){
							if(authorityBizBean != null){
								
								var optionY = '<option value="Y">停用</option>';
								var optionN = '<option value="N">正常</option>';
								if (authorityBizBean.markDelete == 'Y') {
									optionY = '<option value="Y" selected>停用</option>';
								}
								if (authorityBizBean.markDelete == 'N') {
									optionN = '<option value="N" selected>正常</option>';
								}
								var body = '<form action="authAction!updateAuth.do" id="authform" name="authform" method="post">' +
								'<input type="hidden" id="authId" value="'+authorityBizBean.id+'"/>'+
								'<div class="row"><b class="label">权限名称:</b><input id="name" value="'+authorityBizBean.name+'" class="input" readonly="readonly" style="background-color: #DDDDDD;border: 0px;" />&nbsp;&nbsp;<font color="red" id="message">*</font></div>' +
								'<div class="row"><b class="label">权限状态:</b>'+
								'<select name="status" id="status" style="margin-top: 5px;">' +
								optionN+
								optionY+		
								'</select><font color="red">&nbsp;&nbsp;*</font>' +
								'</div>' +
								'<div class="row"><b class="label">备注:</b><textarea id="roleRemark" rows="3" class="input" style="textmode:multiline;" onkeydown="if (this.value.length>=200){event.returnValue=false}">'+authorityBizBean.description+'</textarea></div>' +		
								'</form>';
								var	footer='<div style="text-align:center"><input type="button" value="保存" class="divbtn" id="authUpdate"/><input type="button" value="取消" class="divbtn" id="authcancel" /></div>';
								Box("auth",400,200,body,"编辑权限",footer);
							}
				   }
				});
		} else if(item == undefined || item <= 0 ) {
			alert("您还没有选择数据!");
			return false;
		} else {
			alert("您只能选择一条数据!");
			return false;
		}
	});
	
	$("#authUpdate").live("click", function(){
		if("" == $("#name").val()){
			$("#message").html("权限名称不能为空！");
			return false;
		} else {
			$("#message").html("*");
		}
		$.ajax({
			   type: "POST",
			   url: "<%=request.getContextPath()%>/system/authAction!update.do",
			   data:{'authorityBizBean.id':$("#authId").val(),
				     'authorityBizBean.name':$("#name").val(),
				     'authorityBizBean.description':$("#roleRemark").val(),
				     'authorityBizBean.markDelete':$("#status").val()
				    },
			   dataType: "json",
			   async: false,
			   success: function(msg){
						if(msg.msg !=''){
							$("#message").html(msg.msg);
						} else {
							alert("权限更新成功！");
							$("#form1").attr("action", "<%=request.getContextPath()%>/system/authAction!getAuthList.do");
							$("#form1").submit();   
						}
			   }
			});
	});
	$("#disable").click(function(){
		var item = $("input[name='authIdList']:checked").length;
		if(item > 0) {
			var ids = "";
			$("input[name='authIdList']:checked").each(function(){
				ids+=$(this).val()+",";
			});
 			if(confirm("您确定要停用选中的数据？")) {
				$.ajax({
					   type: "POST",
					   url: "<%=request.getContextPath()%>/system/authAction!delete.do",
					   data:{'ids':ids
						    },
					   dataType: "json",
					   async: false,
					   success: function(msg){
								if(msg.msg !=''){
									$("#message").html(msg.msg);
								} else {
									alert("权限停用成功！");
									$("#form1").attr("action", "<%=request.getContextPath()%>/system/authAction!getAuthList.do");
									$("#form1").submit();   
								}
					   }
					});
			}
		} else {
			alert("您还没有选择要停用的数据！");
		}
	});
	
	$("#enable").click(function(){
		var item = $("input[name='authIdList']:checked").length;
		if(item > 0) {
			var ids = "";
			$("input[name='authIdList']:checked").each(function(){
				ids+=$(this).val()+",";
			});
 			if(confirm("您确定要启用选中的数据？")) {
				$.ajax({
					   type: "POST",
					   url: "<%=request.getContextPath()%>/system/authAction!enable.do",
					   data:{'ids':ids
						    },
					   dataType: "json",
					   async: false,
					   success: function(msg){
								if(msg.msg !=''){
									$("#message").html(msg.msg);
								} else {
									alert("权限启用成功！");
									$("#form1").attr("action", "<%=request.getContextPath()%>/system/authAction!getAuthList.do");
									$("#form1").submit();   
								}
					   }
					});
			}
		} else {
			alert("您还没有选择要启用的数据！");
		}
	});
});
</script>
</html>